<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@taglib prefix="mvc" uri="http://www.springframework.org/tags/form" %>
<%@taglib prefix="fmt" uri="http://www.springframework.org/tags" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>收支记录</title>
    <link rel="stylesheet" href="/lib/layui/layui/css/layui.css">
    <script type="text/javascript" src="/js/news/jquery-1.9.1.js"></script>
    <script type="text/javascript" src="/lib/layui/layui/lay/dest/layui.all.js"></script>
    <script src="/js/base/base.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/layui/layui/layui.js"></script>
    <script src="/lib/jQuery-File-Upload-master/jquery-1.8.3.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/jQuery-File-Upload-master/jquery.ui.widget.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/jQuery-File-Upload-master/jquery.iframe-transport.js" type="text/javascript"
            charset="utf-8"></script>
    <script src="/lib/jQuery-File-Upload-master/jquery.fileupload.js" type="text/javascript" charset="utf-8"></script>
    <script src="/js/ajaxupload.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/jquery.form.min.js"></script>
    <script type="text/javascript" src="/js/common/fileupload.js"></script>
    <script src="/js/base/base.js" type="text/javascript" charset="utf-8"></script>
    <script type="text/javascript" src="/lib/highcharts.js"></script>

    <style>
        * {
            font-family: "Microsoft Yahei" !important;
            overflow-y: hidden;
        }

        nav button {
            margin-left: 5px;
            padding: .25rem .5rem;
            font-size: .875rem;
            border-radius: .2rem;
            margin-top: 10px;
        }

        nav div {
            float: left !important;
            margin: 15px;
        }

        nav {
            height: 50px;
            border-bottom: 1px solid #cfdbe2;
            background-color: #fafbfc;
            border-radius: 0;
        }

        .layui-tab {
            margin: 0;
        }

        .content {
            height: 544px;
            overflow: auto;
            margin: 14px;
            padding: 14px;
            background: #fff;
            padding-top: 30px;
        }

        .layui-tab-content {
            background-color: #F5F7FA;
        }

        .search {
            display: inline;
            margin-bottom: 1px;
            width: 160px;
            border: 0;
            background: #fafbfc;
        }

        .allBtn {
            float: left !important;
            margin-top: 10px;
            width: 70px;

            border: none;
            background: #fafbfc;
        }

        .screen {
            float: left !important;
            margin-top: 10px;
            width: 100px;
            margin-left: 27px;
            border-radius: 5px;
            color: black;
            border-color: #03a9f4;
            background: #fafbfc;
            border: none;
        }

        .one {
            border: 1px solid #03a9f4;
            border-radius: 5px;
            color: #03a9f4;
            border-color: #03a9f4;
            background: #fafbfc;
        }

        div .layui-input-inline {
            padding-left: 25px;
        }

        #icon {
            width: 10px;
            height: 10px;
            border-radius: 7px;
            margin: 3px auto;
            background: #2196f3;
        }

        .layui-layedit-iframe {
            height: 100px;
        }

        .layui-layedit {
            display: none;
        }

        .layui-btn-primary {
            border: 1px solid #C9C9C9;
            background-color: #fff;
            color: #555;
        }

        .details {
            background: #f4f4f4
        }

        .details td {
            border: none;
        }

        .planType {
            line-height: 45px;
            padding-left: 20px;
        }

        .planType:hover {
            border-color: #ececec;
            background-color: #ececec;
        }

        .menu ul {
            float: right;
            margin-left: 25px;
        }

        .menu ul li {
            float: right;
            background: white;
            padding: 0 15px;
        }

        .menu {
            position: absolute;
            top: 90px;
            left: 86px;
            z-index: 1000;
            display: none;
            /* float: left; */
            min-width: 160px;
            padding: 15px 30px;
            margin: 2px 0 0;
            font-size: 1rem;
            color: #373a3c;
            text-align: left;
            list-style: none;
            background-color: #fff;
            background-clip: padding-box;
            border: 1px solid rgba(0, 0, 0, 0.15);
            border-radius: .25rem;
        }

        .menu div div {
            margin: 15px 0;
        }

        .recordDesc {
            height: 100px;
        }
    </style>
</head>
<body>
<form class="layui-form layui-row form" action="">
    <div class="layui-col-md3" id="leftTree">
        <nav style="border-right: 1px solid #cfdbe2;" class="layui-collapse" lay-filter="leftTree">
            <div style="float: right !important;display: inline-block;border-bottom: 1px solid #ccc;margin-top: 4px;">
                <input type="text" class="search" placeholder="查询计划名称或编号"/>
                <span style="padding: 5px;color: #999;cursor: pointer;">
                <i class="layui-icon layui-icon-search"></i>
                </span>
            </div>
        </nav>
        <nav style="border-right: 1px solid #cfdbe2;" class="layui-collapse" lay-filter="leftTree">
            <button type="button" class="layui-btn layui-btn-primary layui-btn-sm allBtn one classBtn">全部</button>
            <button type="button" class="layui-btn layui-btn-primary layui-btn-sm screen classBtn" id="screen">更多筛选&nbsp;▼</button>

        </nav>

        <div class="" style="border-right: 1px solid #ccc;">
            <ul class="typeUl" lay-filter="test" style="width: 100%;">

            </ul>
        </div>
    </div>
    <div class="menu">
        <div>
            <%--<div>--%>
            <%--<label style="font-weight: bold;">方案类别</label>--%>
            <%--<ul>--%>
            <%--<li style="background: white" value="3">最近三月</li>--%>
            <%--<li style="background: white" value="2">最近一个月</li>--%>
            <%--<li style="background: white" value="1">最近一周</li>--%>
            <%--</ul>--%>
            <%--</div>--%>
            <%--<div>--%>
            <%--<label style="font-weight: bold;">开始时间</label>--%>
            <%--<ul>--%>
            <%--<li style="background: white" value="3">最近三月</li>--%>
            <%--<li style="background: white" value="2">最近一个月</li>--%>
            <%--<li style="background: white" value="1">最近一周</li>--%>
            <%--</ul>--%>
            <%--</div>--%>
            <div>
                <label style="font-weight: bold;">方案状态</label>
                <ul>
                    <li style="background: white;" value="1">进行中</li>
                    <li style="background: white;" value="2">已结束</li>
                </ul>
            </div>
        </div>
    </div>
    <div class="layui-col-md9">
        <nav>
            <i class="layui-icon layui-icon-prev"
               style="float: left;line-height: 50px;margin-left: 5px;color:#fafbfc "></i>
            <div>收支记录</div>
            <button type="button" class="layui-btn layui-btn-normal layui-btn-sm  addBtn"
                    style="float: right;margin-right: 25px">新建
            </button>
            <button type="button" class="layui-btn layui-btn-primary layui-btn-sm  searchBtn"
                    style="float: right;">搜索</button>
            <input type="text" name="endReTime" id="date1" lay-verify="date" placeholder="结束时间(yyyy-MM-dd HH:mm:ss)" autocomplete="off"
                   class="layui-input" style="float: right;margin: 5px 5px 0 0;width: 20%">
            <input type="text" name="createdReTime" id="date2" lay-verify="date" placeholder="开始时间(yyyy-MM-dd HH:mm:ss)" autocomplete="off"
                   class="layui-input" style="float: right;margin: 5px 5px 0 0;width: 20%">
        </nav>
        <div>
            <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
                <div class="layui-tab-content">
                    <div class="content layui-row">
                        <div class="details " style="display: none">
                            <span class="layui-input-inline"
                                  style="color: #2196f3;padding: 15px 0 0px 13px;">柔柔弱弱 </span>
                            <table class="layui-table " style="background-color:#f4f4f4">
                                <tbody>
                                <tr>
                                    <td>已收入</td>
                                    <td>123,500.00</td>
                                    <td>已支出</td>
                                    <td>0.00</td>
                                    <td>收支差</td>
                                    <td>123,500.00</td>
                                </tr>
                                <tr>
                                    <td>收入预估</td>
                                    <td>0.00</td>
                                    <td>支出预算</td>
                                    <td>0.00</td>
                                    <td>预算收支差</td>
                                    <td></td>
                                </tr>
                                <tr>
                                    <td>计划周期</td>
                                    <td>0天</td>
                                    <td>启动时间</td>
                                    <td>2017-04-25 01:03:39</td>
                                    <td>结束时间</td>
                                    <td>1970-01-01 08:00:00</td>
                                </tr>
                                <tr>
                                    <td>创建人</td>
                                    <td>系统管理员</td>
                                    <td>创建时间</td>
                                    <td>2017-04-25 01:03:39</td>
                                </tr>
                                <tr>
                                    <td>方案描述</td>
                                    <td colspan="3"></td>
                                </tr>
                                </tbody>
                            </table>
                        </div>
                        <hr style="margin: 15px 0;display: none">
                        <div class="statistics" id="record" style="display: none">
                            <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
                                <ul class="layui-tab-title">
                                    <li class="layui-this">线型图</li>
                                    <li>柱形图</li>
                                </ul>
                                <div class="layui-tab-content" style="background: white">
                                    <div class="layui-tab-item layui-show">
                                        <div id="lines"></div>
                                    </div>
                                    <div class="layui-tab-item">
                                        <div id="pillar"></div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="record">

                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</form>
</body>
<script>
    var form,layer,layedit,laydate,element,table;
    layui.use(['form', 'layedit', 'laydate', 'layedit', 'table', 'element'], function () {
        form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate
            , element = layui.element
            , table = layui.table
        //日期
        laydate.render({
            elem: '#date1',
            type:'datetime'
        });
        laydate.render({
            elem: '#date2',
            type:'datetime'
        });

        $(document).on('click', '.planType', function () {
            $('.record').show();
            $('.statistics').hide()
            $(this).css('background', '#03a9f4');
            $(this).siblings().css('background', 'rgb(247, 247, 247)');
            $('.details').show();
            $('hr').show();
            $('#date1').hide();
            $('#date2').hide();
            $('.searchBtn').text('图表展示');
            findRecords($(this).attr('planId'),'','');
            cartogram($(this).attr('planId'))
            $.ajax({
                url: "/IncomePlan/findIncomePlanById",
                type: "get",
                data:{
                    planId:$(this).attr('planId')
                },
                dataType: 'json',
                success: function (data) {
                    var data=data.object
                    var str = ' <span class="layui-input-inline" style="color: #2196f3;padding: 15px 0 0px 13px;">'+data.planName+'</span> ' +
                        '<table class="layui-table " style="background-color:#f4f4f4"> <tbody>'+
                        '<tr> '+
                        '  <td>已收入</td> <td>'+nonNull(data.map.Earned)+'</td>'+
                        '  <td>已支出</td> <td>'+nonNull(data.map.Spent)+'</td>'+
                        '  <td>收支差</td> <td>'+nonNull(data.map.realSubtract)+'</td>'+
                        '   </tr>'+
                        '   <tr>'+
                        '<td>收入预估</td> <td>'+nonNull(data.incomeBudget)+'</td>'+
                        '<td>支出预算</td> <td>'+nonNull(data.expenseBudget)+'</td>'+
                        ' <td>预算收支差</td><td>'+nonNull(data['map'].budgetSubtract)+'</td>'+
                        ' </tr>'+
                        ' <tr>'+
                        '<td>计划周期</td> <td>'+nonNull(data.planCycle)+'天</td>'+
                        '<td>启动时间</td> <td>'+nonNull(data.beginTime)+'</td>'+
                        '<td>结束时间</td> <td>'+function () {
                            if(data.endTime==undefined || data.endTime==''){
                                return '未结束'
                            } else {
                                return data.endTime
                            }
                        }()+'</td>'+
                        '  </tr>'+
                        ' <tr>'+
                        ' <td>创建人</td> <td>'+data.creatorName+'</td>'+
                        ' <td>创建时间</td> <td>'+data.planCreateTime+'</td>'+
                        ' </tr>'+
                        ' <tr>'+
                        '<td>方案描述</td>'+
                        ' <td colspan="3">'+nonNull(data.planDesc)+'</td> </tr> </tbody> </table>'
                    $('.details').html(str)
                }
            });
        });
        findRecords('');
        form.render();
    });
    $('.layui-col-md3 div:last').height($(document.body).height());
    $('.content').height($(window).height() - 130);
    $('.addBtn').click(function () {
        location.href = '/incomeexpense/record/add'
    })
    $('.classBtn').click(function () {
        var index = $('.classBtn').index(this);
        $('.content:eq("' + index + '")').css('display', 'block').siblings('.content').css('display', 'none')
        $(this).toggleClass("one");
        $(this).siblings('button').removeClass("one");
    });
    $(document).on('mouseenter', '.layui-icon-prev', function () {
        $(this).css('color', '#03a9f4')
    }).on('mouseleave', '.layui-icon-prev', function () {
        $(this).css('color', '#fafbfc')
    });
    $(document).on('mouseenter', '.contentRight', function () {
        $(this).children().children().eq(1).show()
    }).on('mouseleave', '.contentRight', function () {
        $(this).children().children().eq(1).hide()
    });

    function delImg(dome) {
        layer.confirm('确定要删除吗？', {
            btn: ['确定', '取消'], //按钮
            title: "删除附件"
        }, function () {
            dome.parents('.dech').remove();
            layer.msg('删除成功', {icon: 6});
            layer.closeAll();

        })
    }
    function nonNull(num) {
        if(num==undefined||num==null){
            return ''
        }else{
            return num
        }
    }
    $(function () {
        planType()
    });
    $('.allBtn').click(function () {
        $('.menu').hide();
        planType()
    });
    $('.menu ul li').click(function () {
        $(this).toggleClass("one");
        $(this).siblings('li').removeClass("one");
        var planStatus=$(this).val();
        var planName=$('.search').val();
        planType(planName,planStatus)
    });
    $('.layui-icon-search').click(function () {
        var planName=$('.search').val();
        planType(planName,'');
    });
    function planType(planName,planStatus) {
        $('.menu').hide();
        $.ajax({
            url: "/IncomePlan/findIncomePlan",
            type: "get",
            data:{
                planName:planName,
                planStatus:planStatus
            },
            dataType: 'json',
            success: function (data) {
                var str = ''
                for (var i = 0; i < data.obj.length; i++) {
                    str += ' <li class="planType" planId=' + data.obj[i].planId + '><a href="#">' + data.obj[i].planName + '</a></li>'
                }
                $('.typeUl').html(str)
            }
        });
    }

    function findRecords(planId,createdReTime,endReTime) {
        $.ajax({
            url: "/IncomeRecords/findRecords",
            type: "post",
            data: {
                planId: planId,
                endReTime:endReTime,
                createdReTime:createdReTime
            },
            dataType: 'json',
            success: function (data) {
                var str = '';
                var data = data.obj;
                if (data.length != 0) {
                    for (var i = 0; i < data.length; i++) {
                        str += '<div class="contentRight">' +
                            '<div class="layui-col-xs2 text" style="padding-left: 58px;margin-top:26px">' +
                            '   <div>' +
                            '   <span style="color: #777;font-size: 12px;">' + data[i].createdReTime.trim().split(" ")[0] + '</span>' +
                            '   <br/>' +
                            '    <span style="color: #444;font-size: 20px;">' + data[i].createdReTime.trim().split(" ")[1] + '</span>' +
                            '  </div>' +
                            ' <div style="padding-left: 30px;padding-top: 10px;display: none">' +
                            '    <button type="button" class="layui-btn layui-btn-normal layui-btn-xs update" recordId="' + data[i].recordId + '" planId="' + data[i].planId + '">编辑</button>' +
                            '   <br/>' +
                            '   <button type="button" class="layui-btn layui-btn-danger layui-btn-xs delect" recordId="' + data[i].recordId + '" planId="' + data[i].planId + '">删除</button>' +
                            '  </div>' +
                            '  </div>' +
                            '  <div class="layui-col-xs1 circle">' +
                            '  <div id="icon"></div>' +
                            '   <div style="width: 1px;height: 270px; background: gainsboro;margin:-3px auto;"></div>' +
                            '   </div>' +
                            '   <div class="layui-col-xs9 tableContent" style="float: right">' +
                            '  <div>' +
                            '  <span class="layui-input-inline" style="color: #2196f3;padding-left:0">' + nonNull(data[i].planName)+ '</span>' +
                            '   <span class="layui-input-inline" style="float: right">创建人 : ' + data[i].creatorName + ' </span>' +
                            '  </div>' +
                            '  <table class="layui-table">' +
                            '     <tbody>' +
                            '     <tr>' +
                            '   <td>支出预算</td>' +
                            '    <td style="color: #f0ad4e !important">￥' + nonNull(data[i].expenseBudget) + '</td>' +
                            ' <td>收入预估</td>' +
                            ' <td>￥' + nonNull(data[i].incomeBudget) + '</td>' +
                            ' </tr> <tr>' +
                            '  <td>本次支出</td>' +
                            '  <td style="color: #f0ad4e !important">' +
                            '     <span>￥' + nonNull(data[i].expense)+ '</span>' +
                            ' <input type="text" id="expend' + nonNull(data[i].recordId) + '" style="display: none" ' +
                            ' autocomplete="off" class="layui-input expend">' +
                            '     </td>' +
                            '     <td>本次收入</td>' +
                            '    <td>' +
                            '     <span>￥' + nonNull(data[i].income) + '</span>' +
                            ' <input type="text" id="income' + nonNull(data[i].recordId) + '" style="display: none" ' +
                            ' autocomplete="off" class="layui-input income ">' +
                            '  </td>' +
                            '  </tr>' +
                            '  <tr>' +
                            '   <td>总支出</td>' +
                            '   <td style="color: #d9534f !important">￥' + nonNull(data[i].realExpense) + '</td>' +
                            ' <td>总收入</td>' +
                            ' <td style="color: #d9534f !important">￥' + nonNull(data[i].realIncome) + '</td>' +
                            ' </tr>' +
                            '  <tr>' +
                            '  <td>相关附件</td>' +
                            ' <td colspan="3">' +
                            '<div id="Attachment" style="padding-bottom:10px">'+function () {
                                //获取附件
                                var attachmentStr = '';
                                var  attachment= data[i].attachmentList;
                                if (attachment != '' && attachment != undefined) {
                                    for (var j = 0; j < attachment.length; j++) {
                                        attachmentStr += '<div class="dech" deUrl="' + attachment[j].attUrl + '"><a href="/download?' + attachment[j].attUrl + '" NAME="' + attachment[j].attachName + '*"><img style="width:16px;" src="/img/file/cabinet@.png"/>' + attachment[j].attachName + '</a><img class="deImgs" onclick="delImg($(this))" style="margin-left:5px;cursor: pointer;" src="/img/file/icon_deletecha_03.png"/><input type="hidden" class="inHidden" value="' + attachment[j].aid + '@' + attachment[j].ym + '_' + attachment[j].attachId + ',"></div>';
                                    }
                                    return attachmentStr
                                }else{
                                    return ''
                                }
                            }()+'</div>' +
                            '<input type="hidden" name="attachmentId" autocomplete="off" class="layui-input">' +
                            ' <input type="hidden" name="attachmentName" autocomplete="off" class="layui-input">' +
                            ' <button id="uploadimg test3" type="button" style="display: none;" ' +
                            'class="layui-btn accessory"><i class="layui-icon"></i>上传附件 </button>' +
                            ' <input type="file" multiple="multiple" name="file" id="uploadinputimg" class="w-icon5"' +
                            'style="position: absolute;opacity: 0;width: 110px;left:18px;height:40px;">' +
                            '  </td>' +
                            ' <tr>' +
                            ' <td>收支产生时间</td>' +
                            ' <td colspan="3">' +
                            '  <span>' + nonNull(data[i].recordTime) + '</span>' +
                            '<input type="text" style="display: none" name="date" id="produceTime' + data[i].recordId + '"' +
                            ' lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off"' +
                            '    class="layui-input produceTime ">' +
                            '  </td>' +
                            '  </tr>' +
                            '  <tr>' +
                            '  <td>备注</td>' +
                            ' <td colspan="3">' +
                            '     <span>' + function () {
                                if (data[i].recordDesc!=undefined){
                                    return data[i].recordDesc;
                                }
                                return '';
                            }() + '</span>' +
                            ' <input type="text" id="recordDesc' + nonNull(data[i].recordId) + '" style="display: none" ' +
                            ' autocomplete="off" class="layui-input recordDesc">' +
                            '   </td>' +
                            '   </tr>' +
                            '   </tbody>' +
                            '  </table>' +
                            '  </div>' +
                            ' </div>'
                    }
                    $('.record').html(str)
                } else {
                    str = '<div class="no_notice" style="text-align: center;border: none;">' +
                        '<img style="margin-top: 62px;"  src="/img/main_img/shouyekong.png" alt="">' +
                        '<h2 style="text-align: center;color: #666;font-size: 14px;margin-top: 10px;">暂无数据</h2>' +
                        '</div>';
                    $('.record').html(str)
                };
                $('#uploadinputimg').click(function () {
                    $('.form').attr('action', '/upload?module=revenue')
                    fileuploadFn('#uploadinputimg', $('#Attachment'));
                })
                $('.delect').click(function () {
                    var recordId=$(this).attr('recordId')
                    var planId=$(this).attr('planId')

                    if ($(this).text() == '取消') {
                        $(this).parents('.contentRight').find('.accessory').hide();
                        $(this).parents('.contentRight').find('.layui-layedit').hide();
                        $(this).parents('.contentRight').find('.produceTime').hide();
                        $(this).parents('.contentRight').find('.expend').hide();
                        $(this).parents('.contentRight').find('.income').hide();
                        $(this).parents('.contentRight').find('.recordDesc').hide();
                        $(this).parents('.contentRight').find('.produceTime').siblings().show();
                        $(this).parents('.contentRight').find('.expend').siblings().show();
                        $(this).parents('.contentRight').find('.income').siblings().show();
                        $(this).parents('.contentRight').find('.recordDesc').siblings().show();
                        $(this).parents('.contentRight').find('.circle div:eq(1)').height($(this).parents('.text').siblings('.tableContent').height())
                        $(this).text('删除').attr('class', 'layui-btn layui-btn-danger layui-btn-xs delect').siblings('button').text('编辑').attr('class', 'layui-btn layui-btn-normal layui-btn-xs update');
                    }else if ($(this).text() == '删除') {
                        layer.confirm('确定要删除吗？', {
                            btn: ['确定', '取消'], //按钮
                            title: "删除"
                        }, function () {
                            $.ajax({
                                url: "/IncomeRecords/deleteRecords",
                                type: "get",
                                data: {
                                    recordId: recordId,
                                    planId: planId
                                },
                                dataType: 'json',
                                success: function (data) {
                                    layer.msg('删除成功', {icon: 6});
                                    layer.closeAll();
                                    location.reload();
                                }
                            })
                        })

                    }
                })
                $('.update').click(function () {
                    var recordId = $(this).attr('recordId');
                    var planId = $(this).attr('planId');
                    laydate.render({
                        elem: '#produceTime' + recordId + ''
                        , type: 'datetime'
                    });
                    if ($(this).text() == '编辑') {

                        $.ajax({
                            url: "/IncomeRecords/findRecordsById",
                            type: "get",
                            data: {
                                recordId: recordId
                            },
                            dataType: 'json',
                            success: function (res) {
                                $('#expend' + recordId + '').val(res.object.expense)
                                $('#income' + recordId + '').val(res.object.income)
                                $('#produceTime' + recordId + '').val(res.object.recordTime)
                                $('#recordDesc' + recordId + '').val(res.object.recordDesc)
                            }
                        });
                        $(this).parents('.contentRight').find('.accessory').show();
                        $(this).parents('.contentRight').find('.layui-layedit').show();
                        $(this).parents('.contentRight').find('.produceTime').show();
                        $(this).parents('.contentRight').find('.expend').show();
                        $(this).parents('.contentRight').find('.income').show();
                        $(this).parents('.contentRight').find('.recordDesc').show();
                        $(this).parents('.contentRight').find('.produceTime').siblings().hide();
                        $(this).parents('.contentRight').find('.expend').siblings().hide();
                        $(this).parents('.contentRight').find('.income').siblings().hide();
                        $(this).parents('.contentRight').find('.recordDesc').siblings().hide();
                        $(this).parents('.contentRight').find('.circle div:eq(1)').height($(this).parents('.text').siblings('.tableContent').height())
                        $(this).text('保存').attr('class', 'layui-btn layui-btn-normal layui-btn-xs save').siblings('button').text('取消').attr('class', 'layui-btn layui-btn-primary layui-btn-xs cancel');
                    } else {
                        //获取附件id和name
                        var attachmentId = '';
                        var attachmentName = '';
                        for (var i = 0; i < $(this).parents('.contentRight').find('.inHidden').length; i++) {
                            attachmentId += $(this).parents('.contentRight').find('.inHidden').eq(i).val();
                        }
                        for (var i = 0; i < $(this).parents('.contentRight').find('.inHidden').length; i++) {
                            attachmentName += $(this).parents('.contentRight').find('a').eq(i).attr('NAME');
                        }
                        $.ajax({
                            url: "/IncomeRecords/editRecords",
                            type: 'POST',
                            data: {
                                planId: planId,
                                recordId: recordId,
                                expense: $('#expend' + recordId + '').val(),
                                income: $('#income' + recordId + '').val(),
                                recordTime: $('#produceTime' + recordId + '').val(),
                                recordDesc: $('#recordDesc' + recordId + '').val(),
                                attachmentId: attachmentId,
                                attachmentName: attachmentName
                            },
                            success: function (res) {
                                if(res.flag){
                                    layer.msg("保存成功", {icon: 1})
                                    location.reload();
                                }
                            }
                        });
                        $(this).parents('.contentRight').find('.accessory').hide();
                        $(this).parents('.contentRight').find('.layui-layedit').hide();
                        $(this).parents('.contentRight').find('.produceTime').hide();
                        $(this).parents('.contentRight').find('.expend').hide();
                        $(this).parents('.contentRight').find('.income').hide();
                        $(this).parents('.contentRight').find('.recordDesc').hide();
                        $(this).parents('.contentRight').find('.produceTime').siblings().show();
                        $(this).parents('.contentRight').find('.expend').siblings().show();
                        $(this).parents('.contentRight').find('.income').siblings().show();
                        $(this).parents('.contentRight').find('.recordDesc').siblings().show();
                        $(this).parents('.contentRight').find('.circle div:eq(1)').height($(this).parents('.text').siblings('.tableContent').height())
                        $(this).text('编辑').attr('class', 'layui-btn layui-btn-normal layui-btn-xs update').siblings('button').text('删除').attr('class', 'layui-btn layui-btn-danger layui-btn-xs delect');
                    }
                });
            }
        });
    }

    $('.searchBtn').click(function () {
        var text=$(this).text()
        if ( text == '图表展示') {
            $('.statistics').show();
            $('.contentRight').hide();
            $('.record').hide();
            $(this).text('列表展示');
        } else if (text == '列表展示') {
            $('.statistics').hide();
            $('.contentRight').show();
            $('.record').show()
            $(this).text('图表展示');
        }else if (text == '搜索') {
            var endReTime=$('[name="endReTime"]').val();
            var createdReTime=$('[name="createdReTime"]').val();
           /* if(endReTime==''){
                var myDate = new Date();
                var year=myDate.getFullYear();        //获取当前年
                var month=myDate.getMonth()+1;   //获取当前月
                var date=myDate.getDate();            //获取当前日
                var h=myDate.getHours();              //获取当前小时数(0-23)
                var m=myDate.getMinutes();          //获取当前分钟数(0-59)
                var s=myDate.getSeconds();
                endReTime=year+'-'+getNow(month)+"-"+getNow(date)+" "+getNow(h)+':'+getNow(m)+":"+getNow(s);
            }*/
            findRecords('',createdReTime,endReTime)
        }
    });
    $('#screen').click(function () {
        if ($(this).is('.one')) {
            $('.menu').show();
        } else {
            $('.menu').hide();
        }
    });

    function cartogram(planId) {
        $.get('/IncomeRecords/findstatistics', {planId: planId}, function (res) {
            var INCOME=[];//收入
            var EXPENSE=[];//支出
            var str=[];
            if(res.object!=''&&res.object!=undefined){
                for(var i=0;i<res.object.length;i++){
                    INCOME.push(res.object[i].INCOME)
                    EXPENSE.push(res.object[i].EXPENSE)
                    str.push(res.object[i].RECORD_TIME.trim().split(" ")[0])
                }
                var chart = Highcharts.chart('lines', {
                    title: {
                        text: '销售收入收支记录图表'
                    },
                    subtitle: {
                        text: ''
                    },
                    credits: {
                        enabled: false
                    },
                    yAxis: {
                        title: {
                            text: '金额'
                        },
                        labels: {
                            formatter: function () {
                                return this.value + '元';
                            }
                        }
                    },
                    legend: {
                        layout: 'vertical',
                        align: 'right',
                        verticalAlign: 'middle'
                    },
                    xAxis: {
                        categories: str
                    },
                    plotOptions: {
                        line: {
                            dataLabels: {
                                // 开启数据标签
                                enabled: true
                            },
                            // 关闭鼠标跟踪，对应的提示框、点击事件会失效
                            enableMouseTracking: false
                        }
                    },
                    series: [{
                        name: '收入',
                        data: INCOME
                    }, {
                        name: '支出',
                        data: EXPENSE
                    }],
                    responsive: {
                        rules: [{
                            condition: {
                                maxWidth: 500
                            },
                            chartOptions: {
                                legend: {
                                    layout: 'horizontal',
                                    align: 'center',
                                    verticalAlign: 'bottom'
                                }
                            }
                        }]
                    }
                });
                $("#pillar").highcharts({
                    chart: {
                        type: 'column'
                    },
                    title: {
                        text: '费用统计报表'
                    },
                    subtitle: {
                        text: ''
                    },
                    xAxis: {
                        categories: str
                    },
                    yAxis: {
                        title: {
                            text: '金额'
                        },
                        labels: {
                            formatter: function () {
                                return this.value + '元';
                            }
                        }
                    },
                    credits: {
                        enabled: false
                    },
                    plotOptions: {
                        line: {
                            dataLabels: {
                                enabled: false          // 开启数据标签
                            },
                            enableMouseTracking: true, // 关闭鼠标跟踪，对应的提示框、点击事件会失效
                            showInLegend: false
                        }
                    },
                    series: [{
                        name: '收入',
                        data: INCOME
                    }, {
                        name: '支出',
                        data: EXPENSE
                    }],
                });
            }else{
                $('#lines').html('<div class="no_notice" style="text-align: center;border: none;">' +
                    '<img style="margin-top: 62px;"  src="/img/main_img/shouyekong.png" alt="">' +
                    '<h2 style="text-align: center;color: #666;font-size: 14px;margin-top: 10px;">暂无数据</h2>' +
                    '</div>'
                )
                $('#pillar').html('<div class="no_notice" style="text-align: center;border: none;">' +
                    '<img style="margin-top: 62px;"  src="/img/main_img/shouyekong.png" alt="">' +
                    '<h2 style="text-align: center;color: #666;font-size: 14px;margin-top: 10px;">暂无数据</h2>' +
                    '</div>'
                )
            }

        });
    }
    //判断是否在前面加0
    function getNow(s) {
        return s < 10 ? '0' + s: s;
    }
</script>

</html>
